import { reactive } from 'vue';
// import { mesConfig } from "@erp/mes.config"
import { setLocal } from '@/utils/auth';
import notification from '@arco-design/web-vue/es/notification';
import { userUserLogin } from '@/api/url/erp/login';
import router from '@/router';
import userInFoPinia from "@pinia/modules/user";
// const { STYLE_name } = mesConfig()
export default function importConfig() {
  /**
   * @param STYLE_name 系统名称
   * @param userData 登入信息载体
   *        @param userId 账号
   *        @param password 密码
   * @param loginLD  登入按钮加载动画
   */
  const base = reactive<any>({
    STYLE_name: '台州欧博MES管理系统',
    userData: {
      userId: '',
      password: '',
    },
    loginLD: false,
  });

  /**
   * @export login 登入方法
   */
  const login = () => {
    base.loginLD = true;

    // const steam = setTimeout(() => {
    //   notification.error('登入出现错误,请联系管理员');
    //   base.loginLD = false;
    // }, 5000);

    const userStore = userInFoPinia();

    userUserLogin({
      MV001: base.userData.userId,
      UDF01: base.userData.password,
    }).then((res: any) => {
      console.log(res);
      if (res.code == '200') {
        // localStorage.setItem('TOKEN', res.data.token);
        // localStorage.setItem('userName', res.data.userName);
        localStorage.setItem('userId', res.data);
        notification.success('登入成功');

        //判断当前用户是否有删除权限
        if(userStore.adminList.includes(base.userData.userId)){
          userStore.setAuthenticationStatus(true, true);
        }

        // clearTimeout(steam);
        router.push('/queyrOddModel');
      } else {
        notification.success(res.msg);
        base.loginLD = false;
      }
    });
  };

  return {
    base,
    login,
  };
}
